#include <iostream>
#define MAX 100005
using namespace std;
int main()
{
    int P[MAX], A[MAX];
    int j = 1, k = 1, count = 0, st = 1,ed = 0,sum=0;
    fill(P,P+MAX,0);
    fill(A,A+MAX,0);
    string str;
    cin >> str;
    for (int i = str.length() - 1; i >= 0; i--)
    {
        if (str[i] == 'T')
            count++;
        else if (str[i] == 'A')
        {
            A[j] = A[j-1] + count;
            j ++;
            count = 0;
        }
        else if (str[i] == 'P')
        {
            int p;
            P[k] = P[k-1];
            for(p = st; p < j; p ++)
                P[k] += A[p];
            st = j;
            sum = (sum + P[k]) % 1000000007;
            k++;
        }
    }
    cout << sum;
    return 0;
}